package org.itboys.mysql.entity;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.itboys.mysql.utils.BeanUtils;

/**
 * Bean基础类
 * Created by wiesky on 2017/2/4.
 */
public abstract class BaseBean implements Cloneable, Serializable {

	private static final long serialVersionUID = -3707046914855595598L;

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

	/**
	 * 浅层复制(如果属性为引用类型则只复制属性的引用值)当前对象
	 */
	public <T> T simpleClone() {
		try {
			@SuppressWarnings("unchecked")
			T ret = (T)clone();
			return ret;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * 获取指定属性的值集合
	 */
	public List<Object> getFieldValues(List<String> fieldNames) {
		return BeanUtils.toList(this, fieldNames.toArray(new String[0]));
	}

	/**
	 * 将当前对象转换成属性和值的映射
	 * 
	 * @return
	 * @created 2013-4-18
	 * @author  huanglj
	 */
	public Map<String, Object> toFieldMapping() {
		return BeanUtils.toMap(this);
	}

}
